/**
 * 
 */
package fr.gfi.agraf.vue.action.gerer.saisie;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import fr.gfi.agraf.exception.AgrafException;
import fr.gfi.agraf.service.IPerimetreService;
import fr.gfi.agraf.utils.PropertiesUtils;
import fr.gfi.agraf.utils.SpringFactory;
import fr.gfi.agraf.vue.action.AbstractApplicationSupportAction;
import fr.gfi.agraf.vue.bean.PerimetreDTO;

/**
 * @author Zakaria
 * 
 */
public class VoirSaisieAction extends AbstractApplicationSupportAction {

	/**
	 * Logger
	 */
	private final static Logger LOGGER = Logger.getLogger(VoirSaisieAction.class);

	private static final String PERIMETRE_SERVICE = "PerimetreService";

	private static final String POPUP_AIDE_SAISIE = "popup.aide.saisie";

	private boolean reinit;
	/**
	 * 
	 */
	private static final long serialVersionUID = 5695099241457200002L;

	private List<PerimetreDTO> perimetreList;

	private List<String> listeInfoPage;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * fr.gfi.agraf.vue.action.AbstractApplicationSupportAction#executeAction()
	 */
	@Override
	public String executeAction() throws Exception {
		// Spring, recupere le service perimetre
		final IPerimetreService perimetreService = (IPerimetreService) SpringFactory.getApplicationContext()
				.getBean(PERIMETRE_SERVICE);

		try {
			// fait appel au service perimetre
			setPerimetreList(perimetreService.getListePerimetreByUtilisateurID(getUtilisateurConnecte()
					.getId()));
		} catch (final AgrafException ae) {
			// Recupére le message
			final String message = PropertiesUtils.getProperty(ae.getKey());
			// Ajoute action message
			addActionMessage(message);
			LOGGER.error(message, ae);
			return ERROR;
		}
		if (null != sessionMap.get(TraiterSaisieAction.REINITIALISER_SAISIE)) {
			reinit = (Boolean) sessionMap.get(TraiterSaisieAction.REINITIALISER_SAISIE);
		}
		sessionMap.put(TraiterSaisieAction.REINITIALISER_SAISIE, false);

		listeInfoPage = new ArrayList<String>();
		listeInfoPage.add(PropertiesUtils.getProperty(POPUP_AIDE_SAISIE));

		return SUCCESS;

	}

	/**
	 * @return the perimetreList
	 */
	public List<PerimetreDTO> getPerimetreList() {
		return perimetreList;
	}

	/**
	 * @param perimetreList
	 *            the perimetreList to set
	 */
	public void setPerimetreList(final List<PerimetreDTO> perimetreList) {
		this.perimetreList = perimetreList;
	}

	/**
	 * @return the reinit
	 */
	public boolean isReinit() {
		return reinit;
	}

	/**
	 * @param reinit
	 *            the reinit to set
	 */
	public void setReinit(final boolean reinit) {
		this.reinit = reinit;
	}

	/**
	 * @return the listeInfoPage
	 */
	public List<String> getListeInfoPage() {
		return listeInfoPage;
	}

}
